<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.16"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>LibTools: H:/project/LibTools/src/thread/RecursiveMutex.cpp 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">LibTools
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.16 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','搜索');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_bfedb72b9d87795234454f6223b9ab1e.html">thread</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">RecursiveMutex.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_recursive_mutex_8cpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="_recursive_mutex_8h.html">RecursiveMutex.h</a>&quot;</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160; </div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<a class="code" href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160; </div>
<div class="line"><a name="l00005"></a><span class="lineno"><a class="line" href="class_c_recursive_mutex.html#a4ef28266819d01562d3fdeb734cc8068">    5</a></span>&#160;<a class="code" href="class_c_recursive_mutex.html#a4ef28266819d01562d3fdeb734cc8068">CRecursiveMutex::CRecursiveMutex</a>()</div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;{</div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;     <a class="code" href="class_c_recursive_mutex.html#a6990296f98781a07e0d151cac9177ebf">_lockCount</a> = 0;</div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;     <a class="code" href="class_c_recursive_mutex.html#ad277df2b191cd54075130d175c72c4c0">_lockThreadId</a> = 0;</div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;}</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno"><a class="line" href="class_c_recursive_mutex.html#a6a81b3d2450ff8f1c06874c6ea85be67">   11</a></span>&#160;<a class="code" href="class_c_recursive_mutex.html#a6a81b3d2450ff8f1c06874c6ea85be67">CRecursiveMutex::~CRecursiveMutex</a>()</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;{</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;     <a class="code" href="class_c_recursive_mutex.html#a6990296f98781a07e0d151cac9177ebf">_lockCount</a> = 0;</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;     <a class="code" href="class_c_recursive_mutex.html#ad277df2b191cd54075130d175c72c4c0">_lockThreadId</a> = 0;</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;}</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160; </div>
<div class="line"><a name="l00017"></a><span class="lineno"><a class="line" href="class_c_recursive_mutex.html#aba7f1be4b2bff1dd9375cc90e05941bb">   17</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_c_recursive_mutex.html#aba7f1be4b2bff1dd9375cc90e05941bb">CRecursiveMutex::Lock</a>()</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;{</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;    <span class="keywordtype">long</span> curThreadId = <a class="code" href="namespace_share_api.html#aa247d107f7e439e2c6871dfba195a022">ShareApi::GetCurrentThreadId</a>();</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;    <span class="keywordflow">if</span> (!<a class="code" href="class_c_recursive_mutex.html#abc05b7ff3fcce00bfe0354f6a0b2700c">Test_Recursive</a>(curThreadId))</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;    {</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;         <a class="code" href="class_c_recursive_mutex.html#a6c9cfe5901d3efd81bc53da3d5edc9e5">_mutex</a>.<a class="code" href="class_c_mutex.html#af673eb768848738ed476d4ce2e2eb443">Lock</a>();</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;        <a class="code" href="namespace_share_api.html#aa020decf062bbd8dc399dd69c67a1d5b">ShareApi::InterlockedExchange</a>(&amp;<a class="code" href="class_c_recursive_mutex.html#ad277df2b191cd54075130d175c72c4c0">_lockThreadId</a>, curThreadId);</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;         <a class="code" href="class_c_recursive_mutex.html#a6990296f98781a07e0d151cac9177ebf">_lockCount</a> = 1;</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    }</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;}</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160; </div>
<div class="line"><a name="l00028"></a><span class="lineno"><a class="line" href="class_c_recursive_mutex.html#a23d5b6de26ead85da2c13ec5f523ceec">   28</a></span>&#160;<span class="keywordtype">void</span> <a class="code" href="class_c_recursive_mutex.html#a23d5b6de26ead85da2c13ec5f523ceec">CRecursiveMutex::Unlock</a>()</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;{</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="keywordflow">if</span> (!--<a class="code" href="class_c_recursive_mutex.html#a6990296f98781a07e0d151cac9177ebf">_lockCount</a>)</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    {</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;        <a class="code" href="namespace_share_api.html#aa020decf062bbd8dc399dd69c67a1d5b">ShareApi::InterlockedExchange</a>(&amp;<a class="code" href="class_c_recursive_mutex.html#ad277df2b191cd54075130d175c72c4c0">_lockThreadId</a>, 0);</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;         <a class="code" href="class_c_recursive_mutex.html#a6c9cfe5901d3efd81bc53da3d5edc9e5">_mutex</a>.<a class="code" href="class_c_mutex.html#ac0a6922590d43c88d9343feac2ccba2c">Unlock</a>();</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    }</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;}</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160; </div>
<div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="class_c_recursive_mutex.html#a0d5f2e5a91c7757d0eeb3f4f6a816289">   37</a></span>&#160;<a class="code" href="tools_8h.html#a01e895c2df346ffe662bbe69686d8d51">SYNCHANDLE</a> <a class="code" href="class_c_recursive_mutex.html#a0d5f2e5a91c7757d0eeb3f4f6a816289">CRecursiveMutex::Handle</a>()</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;{</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="class_c_recursive_mutex.html#a6c9cfe5901d3efd81bc53da3d5edc9e5">_mutex</a>.<a class="code" href="class_c_mutex.html#aef8094fb14fbccf8e095b162ba90dade">Handle</a>();</div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;}</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160; </div>
<div class="line"><a name="l00042"></a><span class="lineno"><a class="line" href="class_c_recursive_mutex.html#abc05b7ff3fcce00bfe0354f6a0b2700c">   42</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="class_c_recursive_mutex.html#abc05b7ff3fcce00bfe0354f6a0b2700c">CRecursiveMutex::Test_Recursive</a>(<span class="keywordtype">long</span> curThreadId)</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;{</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    <span class="keywordflow">if</span>(<a class="code" href="namespace_share_api.html#a83771e6812aba75449e79e18b9220041">ShareApi::InterlockedExchangeAdd</a>(&amp;<a class="code" href="class_c_recursive_mutex.html#ad277df2b191cd54075130d175c72c4c0">_lockThreadId</a>, 0) == curThreadId)</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;    {</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    }</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160; </div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;}</div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160; </div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;<a class="code" href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclass_c_recursive_mutex_html_a23d5b6de26ead85da2c13ec5f523ceec"><div class="ttname"><a href="class_c_recursive_mutex.html#a23d5b6de26ead85da2c13ec5f523ceec">CRecursiveMutex::Unlock</a></div><div class="ttdeci">virtual void Unlock()</div><div class="ttdef"><b>Definition:</b> <a href="_recursive_mutex_8cpp_source.html#l00028">RecursiveMutex.cpp:28</a></div></div>
<div class="ttc" id="aclass_c_recursive_mutex_html_ad277df2b191cd54075130d175c72c4c0"><div class="ttname"><a href="class_c_recursive_mutex.html#ad277df2b191cd54075130d175c72c4c0">CRecursiveMutex::_lockThreadId</a></div><div class="ttdeci">long _lockThreadId</div><div class="ttdef"><b>Definition:</b> <a href="_recursive_mutex_8h_source.html#l00025">RecursiveMutex.h:25</a></div></div>
<div class="ttc" id="aclass_c_recursive_mutex_html_abc05b7ff3fcce00bfe0354f6a0b2700c"><div class="ttname"><a href="class_c_recursive_mutex.html#abc05b7ff3fcce00bfe0354f6a0b2700c">CRecursiveMutex::Test_Recursive</a></div><div class="ttdeci">bool Test_Recursive(long dwThread)</div><div class="ttdef"><b>Definition:</b> <a href="_recursive_mutex_8cpp_source.html#l00042">RecursiveMutex.cpp:42</a></div></div>
<div class="ttc" id="atools_8h_html_a201ce692c9dca6599e5c12d00167419b"><div class="ttname"><a href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div><div class="ttdeci">#define DEF_BEG_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00036">tools.h:36</a></div></div>
<div class="ttc" id="aclass_c_recursive_mutex_html_aba7f1be4b2bff1dd9375cc90e05941bb"><div class="ttname"><a href="class_c_recursive_mutex.html#aba7f1be4b2bff1dd9375cc90e05941bb">CRecursiveMutex::Lock</a></div><div class="ttdeci">virtual void Lock()</div><div class="ttdef"><b>Definition:</b> <a href="_recursive_mutex_8cpp_source.html#l00017">RecursiveMutex.cpp:17</a></div></div>
<div class="ttc" id="anamespace_share_api_html_aa247d107f7e439e2c6871dfba195a022"><div class="ttname"><a href="namespace_share_api.html#aa247d107f7e439e2c6871dfba195a022">ShareApi::GetCurrentThreadId</a></div><div class="ttdeci">LIBTOOLS ULONG GetCurrentThreadId()</div><div class="ttdoc">获取当前线程ID</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l01163">ShareApi.cpp:1163</a></div></div>
<div class="ttc" id="aclass_c_recursive_mutex_html_a0d5f2e5a91c7757d0eeb3f4f6a816289"><div class="ttname"><a href="class_c_recursive_mutex.html#a0d5f2e5a91c7757d0eeb3f4f6a816289">CRecursiveMutex::Handle</a></div><div class="ttdeci">virtual SYNCHANDLE Handle()</div><div class="ttdef"><b>Definition:</b> <a href="_recursive_mutex_8cpp_source.html#l00037">RecursiveMutex.cpp:37</a></div></div>
<div class="ttc" id="aclass_c_recursive_mutex_html_a6a81b3d2450ff8f1c06874c6ea85be67"><div class="ttname"><a href="class_c_recursive_mutex.html#a6a81b3d2450ff8f1c06874c6ea85be67">CRecursiveMutex::~CRecursiveMutex</a></div><div class="ttdeci">virtual ~CRecursiveMutex()</div><div class="ttdef"><b>Definition:</b> <a href="_recursive_mutex_8cpp_source.html#l00011">RecursiveMutex.cpp:11</a></div></div>
<div class="ttc" id="atools_8h_html_ac909db71799bb22cb7d636a34cd785e4"><div class="ttname"><a href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div><div class="ttdeci">#define DEF_END_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00038">tools.h:38</a></div></div>
<div class="ttc" id="aclass_c_mutex_html_ac0a6922590d43c88d9343feac2ccba2c"><div class="ttname"><a href="class_c_mutex.html#ac0a6922590d43c88d9343feac2ccba2c">CMutex::Unlock</a></div><div class="ttdeci">virtual void Unlock()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00029">Mutex.cpp:29</a></div></div>
<div class="ttc" id="aclass_c_mutex_html_af673eb768848738ed476d4ce2e2eb443"><div class="ttname"><a href="class_c_mutex.html#af673eb768848738ed476d4ce2e2eb443">CMutex::Lock</a></div><div class="ttdeci">virtual void Lock()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00023">Mutex.cpp:23</a></div></div>
<div class="ttc" id="aclass_c_recursive_mutex_html_a4ef28266819d01562d3fdeb734cc8068"><div class="ttname"><a href="class_c_recursive_mutex.html#a4ef28266819d01562d3fdeb734cc8068">CRecursiveMutex::CRecursiveMutex</a></div><div class="ttdeci">CRecursiveMutex()</div><div class="ttdef"><b>Definition:</b> <a href="_recursive_mutex_8cpp_source.html#l00005">RecursiveMutex.cpp:5</a></div></div>
<div class="ttc" id="aclass_c_recursive_mutex_html_a6c9cfe5901d3efd81bc53da3d5edc9e5"><div class="ttname"><a href="class_c_recursive_mutex.html#a6c9cfe5901d3efd81bc53da3d5edc9e5">CRecursiveMutex::_mutex</a></div><div class="ttdeci">CMutex _mutex</div><div class="ttdef"><b>Definition:</b> <a href="_recursive_mutex_8h_source.html#l00024">RecursiveMutex.h:24</a></div></div>
<div class="ttc" id="aclass_c_mutex_html_aef8094fb14fbccf8e095b162ba90dade"><div class="ttname"><a href="class_c_mutex.html#aef8094fb14fbccf8e095b162ba90dade">CMutex::Handle</a></div><div class="ttdeci">virtual SYNCHANDLE Handle()</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8cpp_source.html#l00035">Mutex.cpp:35</a></div></div>
<div class="ttc" id="a_recursive_mutex_8h_html"><div class="ttname"><a href="_recursive_mutex_8h.html">RecursiveMutex.h</a></div></div>
<div class="ttc" id="anamespace_share_api_html_aa020decf062bbd8dc399dd69c67a1d5b"><div class="ttname"><a href="namespace_share_api.html#aa020decf062bbd8dc399dd69c67a1d5b">ShareApi::InterlockedExchange</a></div><div class="ttdeci">LIBTOOLS long InterlockedExchange(long *Addend, long value)</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l01754">ShareApi.cpp:1754</a></div></div>
<div class="ttc" id="anamespace_share_api_html_a83771e6812aba75449e79e18b9220041"><div class="ttname"><a href="namespace_share_api.html#a83771e6812aba75449e79e18b9220041">ShareApi::InterlockedExchangeAdd</a></div><div class="ttdeci">LIBTOOLS long InterlockedExchangeAdd(long *Addend, long Value)</div><div class="ttdef"><b>Definition:</b> <a href="_share_api_8cpp_source.html#l01727">ShareApi.cpp:1727</a></div></div>
<div class="ttc" id="aclass_c_recursive_mutex_html_a6990296f98781a07e0d151cac9177ebf"><div class="ttname"><a href="class_c_recursive_mutex.html#a6990296f98781a07e0d151cac9177ebf">CRecursiveMutex::_lockCount</a></div><div class="ttdeci">long _lockCount</div><div class="ttdef"><b>Definition:</b> <a href="_recursive_mutex_8h_source.html#l00026">RecursiveMutex.h:26</a></div></div>
<div class="ttc" id="atools_8h_html_a01e895c2df346ffe662bbe69686d8d51"><div class="ttname"><a href="tools_8h.html#a01e895c2df346ffe662bbe69686d8d51">SYNCHANDLE</a></div><div class="ttdeci">#define SYNCHANDLE</div><div class="ttdoc">异步函数句柄</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00329">tools.h:329</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.16
</small></address>
</body>
</html>
